<template>
	<view>
		<!-- 搜索 -->
		<view class="search">
			<u-row gutter="16">
				<u-col span="11">
					<view>
						<u-search placeholder="请输入你要搜索的物品"
							input-align="center" 
							v-model="keyword"
							:show-action="false"></u-search>
					</view>
				</u-col>
				<u-col span="1">
					<view>
						<u-icon name="search" size="50" @click="searchGoods()"></u-icon>
					</view>
				</u-col>
			</u-row>

		</view>
		<!-- 物品列表 -->
		<view>
			<u-table border-color="#ffffff" font-size="24">
				<u-tr>
					<u-th>图标</u-th>
					<u-th width="25%">名称</u-th>
					<u-th>要求</u-th>
					<u-th>品质</u-th>
					<u-th>类型</u-th>
					<u-th>部位</u-th>
				</u-tr>
				<u-tr v-for="(item,index) in list" style="line-height: 70rpx;">
					<u-td>
						<u-avatar :src="urls+item.img" mode="square" size="70"  @click="descs(item.goods_id)"></u-avatar>
					</u-td>
					<u-td width="25%">{{item.title}}</u-td>
					<u-td>{{item.demand}}</u-td>
					<u-td>{{item.quality}}</u-td>
					<u-td>{{item.type}}</u-td>
					<u-td>{{item.position}}</u-td>
				</u-tr>
			</u-table>
		</view>
		<!-- 遮罩层 -->
		<u-mask :show="show" @click="show = false">
			<view class="warp">
				<view class="rect" @tap.stop>
					<u-parse :html="content"></u-parse>
				</view>
			</view>
		</u-mask>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyword: '',
				list: [],
				urls: "",
				content: " ",
				show: false
			};
		},
		onLoad() {
			this.urls = getApp().globalData.urls;
			this.getGoods()
		},
		methods:{
			// 获取物品
			getGoods(){
				this.$u.get('/api.goods/index', {}, {
					token: 'token'
				}).then(res => {
					if(res.code == 100){
						this.list = res.data
					}
				});
			},
			//显示商品详情
			descs(gid){
				this.$u.get('/api.goods/desc', {
					gid: gid,
				}, {}).then(res => {
					console.log(res);
					this.content = res.data.content 
					this.show = true
				});
			},
			// 搜索商品
			searchGoods(){
				this.$u.get('/api.goods/index', {
					name: this.keyword,
				}, {}).then(res => {
					console.log(res);
					if(res.code == 100){
						this.list = res.data
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.search{
		padding: 20rpx;
	}
	.warp {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100%;
	}

	.rect {
		border-radius: 20rpx;
		opacity: 0.8;
		padding: 20rpx;
		width: 300px;
		background-color: #fff;
	}
</style>
